package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    private UserService service = new UserServiceImpl();
    public Object getUserByIdByPass(HttpServletRequest request) throws Exception{
        //获取请求参数
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        //调用service的方法
        User user = service.getUserByIdByPass(userId, password);
        return user;
    }
    public Object getUserById(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        int row = service.getUserById(userId);
        System.out.println(row);
        return row;
    }
    public Object saveUser(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        String userName = request.getParameter("userName");
        Integer userSex = Integer.valueOf(request.getParameter("userSex"));
        //String userImg = request.getParameter("userImg");
        User user = new User();
        user.setUserId(userId);
        user.setPassword(password);
        user.setUserName(userName);
        user.setUserSex(userSex);
        //user.setUserImg(userImg);
        int row = service.saveUser(user);
        return row;
    }
}
